# -*-coding:utf-8-*-
import sys

from PyQt5.Qt import *


class ImageLabel(QLabel):

    mouse_move_signal = pyqtSignal()

    def __init__(self, parent):
        super(ImageLabel, self).__init__(parent)
        self.rb = QRubberBand(QRubberBand.Rectangle, self)
        self.origin_point = None
        self.mouse_rect = QRect(0, 0, 1, 1)

    def box_rect(self):
        return self.rect

    def mousePressEvent(self, evt) -> None:
        self.origin_point = evt.pos()
        self.rb.setGeometry(QRect(self.origin_point, QSize()))
        self.rb.show()

    def mouseMoveEvent(self, evt) -> None:
        self.rb.setGeometry(QRect(self.origin_point, evt.pos()).normalized())

    def mouseReleaseEvent(self, evt) -> None:
        self.mouse_rect = self.rb.geometry()
        if self.mouse_rect:
            self.mouse_move_signal.emit()
        self.rb.hide()

        # print("coords", self.rect.getCoords())  # (x, y, x', y')
        # print("rect", self.rect.getRect())      # (x, y, width, height)


class SegmentModeComboBox(QComboBox):
    def __init__(self, parent):
        super(SegmentModeComboBox, self).__init__(parent)
        self.setup_ui()
        self.setEditable(True)
        self.lineEdit().setAlignment(Qt.AlignCenter)

    def setup_ui(self):
        self.addItem("分割")
        self.addItem("精分割")
        self.addItem("去除区域")
        self.addItem("选择区域")
        # self.setView(QAbstractItemView, itemView=QListView())


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = QWidget()
    label = ImageLabel(window)
    label.setText("hahah")
    label.resize(500, 500)
    window.show()
    sys.exit(app.exec_())

